package mid;

public class a61_旋转链表 {
    public ListNode rotateRight(ListNode head, int k) {
        if (head == null || k == 0) {
            return head;
        }
        int tot=0;
        ListNode node=head;
        while (node.next!=null){
            node=node.next;
            tot++;
        }
        ++tot;
        if(k%tot==0){
            return head;
        }
        node.next=head;
        k=tot-k%tot-1;
        while (k-->0){
            head=head.next;
        }
        ListNode node1=head.next;
        head.next=null;
        return node1;
    }
}
